<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Danh sách người dùng</title>
<script type="text/javascript">
function confirmBan()
{
	if(confirm('Xác nhận khóa TK thành viên')==false) return false;
}
function confirmActive()
{
	if(confirm('Xác nhận kích hoạt TK thành viên')==false) return false;
}
function confirmRemove()
{
	if(confirm('Xác nhận xóa TK thành viên')==false) return false;
}
</script>
</head>

<body>
<?php
	include("include/db_connect.php");
	
	$query = mysql_query("Select * from dc_user");	
	$rowTotal = mysql_num_rows($query);
	$rowPage = 1;
	$pageNumber = ceil($rowTotal/$rowPage);
	$pageIndex = $_REQUEST["page"];
	if($pageIndex==null) $pageIndex=1;
	$offset = ($pageIndex-1)*$rowPage;
	
	$query1 = mysql_query("Select * from dc_user LIMIT $offset,$rowPage");
?>
<table width="100%" border="0">
  <caption>
    Danh sách người dùng
  </caption>
  <tr>
    <td>Tên tài khoản</td>
    <td>Trạng thái</td>
    <td>Cấp truy cập</td>
	<td colspan="4">Thao tác</td>
  </tr>
  <?php while($row = mysql_fetch_array($query1)){ ?>
  <tr>
    <td><?php echo $row[0]; ?></td>
    <td>
	<?php 
		if($row[7]==0) 
		{
			echo "Offline";
		}
		else if ($row[7]==1)
		{
			echo "Online";
		}
		else if ($row[7]==2)
		{
			echo "Banned";
		}
	?>
	
	</td>
    <td>
	<?php 
		if($row[8]==2) 
		{
			echo "Admin";
		}
		else if ($row[8]==0)
		{
			echo "Member";
		}
		else if ($row[8]==1)
		{
			echo "Provider";
		}
		//echo $row[8];
	?>
	</td>
	<td><a href="userDetail.php?id=<?php echo $row[0]; ?>&page=<?php echo $pageIndex;?>">Chi tiết</a></td>
	<td>
	<?php if($row[7]==2){ ?>
		<a  href="changeUserState.php?id=<?php echo $row[0];?>&page=<?php echo $pageIndex;?>" onclick="return confirmActive()" >Kích hoạt TK</a>
	<?php }else{ ?>
		<a  href="changeUserState.php?id=<?php echo $row[0]; ?>&page=<?php echo $pageIndex;?>" onclick="return confirmBan()" >Khóa TK</a>
	<?php } ?>
	</td>
	<td><a href="changeUserLevel.php?id=<?php echo $row[0]; ?>&page=<?php echo $pageIndex;?>">Mức độ truy cập</a></td>
	<td><a href="removeUser.php?id=<?php echo $row[0]; ?>&page=<?php echo $pageIndex;?>" onclick="return confirmRemove()">Xóa TK</a></td>
  </tr>
  <?php } ?>
</table>
<p>
<a href="userList.php?page=1">[First] </a>
<?php

if($pageIndex!=1) echo "<a href='userList.php?page=".($pageIndex-1)."'>[Previous] </a>";
for($page=1;$page<=$pageNumber;$page++)
{
	if($page==$pageIndex) echo "<strong>".$page."</strong> ";
	else echo "<a href='userList.php?page=".$page."'>".$page."</a> ";
}
if($pageIndex!=$pageNumber) echo "<a href='userList.php?page=".($pageIndex+1)."'>[Next] </a>";
?>
<a href="userList.php?page=<?php echo $pageNumber; ?>">[Last]</a>
</p>
</body>
</html>
